package com.common.utils.regular;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author xin.ding
 * @date 2020/10/21 19:27
 */
public class TextUtil {

    private static final String CREATE_TABLE="^create\\s+temp\\s+table\\s+(\\w+([-+.]\\w+)*)\\s+as\\s+(select.+)";

    public static void main(String[] args) {
        String text = "链接：https://pan.baidu.com/s/14Ohd4jLuMWLRtqIt6eUNKg\n" +
                "提取码：5dlw\n" +
                "复制这段内容后打开百度网盘手机App，操作更方便哦";
        String link = TextUtil.getLink(text);
        String code = TextUtil.getCode(text);

        System.out.println("link==" + link);
        System.out.println("code==" + code);
    }

    public static String getLink(String text) {
        Pattern pattern = Pattern.compile("链接：(.*)");
        Matcher m = pattern.matcher(text);
        String str = "";
        if (m.find()) {
            str = m.group(1);
        }
        return str;
    }

    public static String getCode(String text) {
        Pattern pattern = Pattern.compile("提取码：(.*)");
        Matcher m = pattern.matcher(text);
        String str = "";
        if (m.find()) {
            str = m.group(1);
        }
        return str;
    }


    public void getLink1() throws Exception {
        String text = "可以的";
        String str = TextUtil.getLink(text);
    }

    public void getCode() throws Exception {
        String text = "链接：https://pan.baidu.com/s/14Ohd4jLuMWLRtqIt6eUNKg\n" +
                "提取码：5dlw\n" +
                "复制这段内容后打开百度网盘手机App，操作更方便哦";
        String str = TextUtil.getCode(text);
    }


    /**
     * 根据正则表达式判断字符是否为汉字
     * 字符串中包含汉字时返回true
     */
    public static boolean hasChinese(String value) {

        // 汉字的Unicode取值范围
        String regex = "[\u4e00-\u9fa5]";
        Pattern pattern = Pattern.compile(regex);
        Matcher match = pattern.matcher(value);

        return match.find();

    }


}